/*
 * $Id: ErrorView.java,v 1.6 2009/07/21 19:37:03 afaichun Exp $
 * 
 * Copyright (C) 2008 General Electric Company. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 * 
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package com.ge.healthcare.autosc.onwatch.view;

import java.io.Writer;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ge.healthcare.autosc.common.ASCLogger;
import com.ge.healthcare.autosc.onwatch.resolver.IXmlMessageResolver;

public class ErrorView extends XmlView {

	IXmlMessageResolver messageResolver = null;
	
	public void render(Map model, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		String methodName = "render";
		ASCLogger.debug(this.getClass(), methodName, "Entered " + methodName);
		// Retrieve data from model
		String errorXml = messageResolver.marshalToXml(model);
		super.setContentType(response);
		// Indicate this is the xml stream is error condition
		response.setHeader("error", "1");
		// Write the XML document to the reponse output stream
		Writer writer = response.getWriter();
		ASCLogger.debug(this.getClass(), "render", "Sending xml:\n" + errorXml);
		writer.write(errorXml);
		writer.close();
	}
	
	public void setMessageResolver(IXmlMessageResolver messageResolver) {
		this.messageResolver = messageResolver;
	}
}
